﻿#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using Dienthoai.Entities;
using Dienthoai.Data;
using Dienthoai.Data.Bases;

#endregion

namespace Dienthoai.Data.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : Dienthoai.Data.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <see cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <see cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "ProductsProductProvider"
			
		private SqlProductsProductProvider innerSqlProductsProductProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsProduct"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsProductProviderBase ProductsProductProvider
		{
			get
			{
				if (innerSqlProductsProductProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsProductProvider == null)
						{
							this.innerSqlProductsProductProvider = new SqlProductsProductProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsProductProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsProductProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsProductProvider SqlProductsProductProvider
		{
			get {return ProductsProductProvider as SqlProductsProductProvider;}
		}
		
		#endregion
		
		
		#region "CommentProvider"
			
		private SqlCommentProvider innerSqlCommentProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Comment"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CommentProviderBase CommentProvider
		{
			get
			{
				if (innerSqlCommentProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCommentProvider == null)
						{
							this.innerSqlCommentProvider = new SqlCommentProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCommentProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlCommentProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCommentProvider SqlCommentProvider
		{
			get {return CommentProvider as SqlCommentProvider;}
		}
		
		#endregion
		
		
		#region "ProductsTypeProvider"
			
		private SqlProductsTypeProvider innerSqlProductsTypeProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsType"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsTypeProviderBase ProductsTypeProvider
		{
			get
			{
				if (innerSqlProductsTypeProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsTypeProvider == null)
						{
							this.innerSqlProductsTypeProvider = new SqlProductsTypeProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsTypeProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsTypeProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsTypeProvider SqlProductsTypeProvider
		{
			get {return ProductsTypeProvider as SqlProductsTypeProvider;}
		}
		
		#endregion
		
		
		#region "ProductsClassProvider"
			
		private SqlProductsClassProvider innerSqlProductsClassProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsClass"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsClassProviderBase ProductsClassProvider
		{
			get
			{
				if (innerSqlProductsClassProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsClassProvider == null)
						{
							this.innerSqlProductsClassProvider = new SqlProductsClassProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsClassProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsClassProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsClassProvider SqlProductsClassProvider
		{
			get {return ProductsClassProvider as SqlProductsClassProvider;}
		}
		
		#endregion
		
		
		#region "MembersProvider"
			
		private SqlMembersProvider innerSqlMembersProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Members"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override MembersProviderBase MembersProvider
		{
			get
			{
				if (innerSqlMembersProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlMembersProvider == null)
						{
							this.innerSqlMembersProvider = new SqlMembersProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlMembersProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlMembersProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlMembersProvider SqlMembersProvider
		{
			get {return MembersProvider as SqlMembersProvider;}
		}
		
		#endregion
		
		
		#region "SupplyProvider"
			
		private SqlSupplyProvider innerSqlSupplyProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Supply"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override SupplyProviderBase SupplyProvider
		{
			get
			{
				if (innerSqlSupplyProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlSupplyProvider == null)
						{
							this.innerSqlSupplyProvider = new SqlSupplyProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlSupplyProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlSupplyProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlSupplyProvider SqlSupplyProvider
		{
			get {return SupplyProvider as SqlSupplyProvider;}
		}
		
		#endregion
		
		
		#region "UserProvider"
			
		private SqlUserProvider innerSqlUserProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="User"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UserProviderBase UserProvider
		{
			get
			{
				if (innerSqlUserProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUserProvider == null)
						{
							this.innerSqlUserProvider = new SqlUserProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUserProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlUserProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUserProvider SqlUserProvider
		{
			get {return UserProvider as SqlUserProvider;}
		}
		
		#endregion
		
		
		#region "ProductsCategoryProvider"
			
		private SqlProductsCategoryProvider innerSqlProductsCategoryProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsCategory"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsCategoryProviderBase ProductsCategoryProvider
		{
			get
			{
				if (innerSqlProductsCategoryProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsCategoryProvider == null)
						{
							this.innerSqlProductsCategoryProvider = new SqlProductsCategoryProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsCategoryProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsCategoryProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsCategoryProvider SqlProductsCategoryProvider
		{
			get {return ProductsCategoryProvider as SqlProductsCategoryProvider;}
		}
		
		#endregion
		
		
		#region "ProductsSimcardProvider"
			
		private SqlProductsSimcardProvider innerSqlProductsSimcardProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsSimcard"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsSimcardProviderBase ProductsSimcardProvider
		{
			get
			{
				if (innerSqlProductsSimcardProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsSimcardProvider == null)
						{
							this.innerSqlProductsSimcardProvider = new SqlProductsSimcardProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsSimcardProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsSimcardProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsSimcardProvider SqlProductsSimcardProvider
		{
			get {return ProductsSimcardProvider as SqlProductsSimcardProvider;}
		}
		
		#endregion
		
		
		#region "ProductsBrandProvider"
			
		private SqlProductsBrandProvider innerSqlProductsBrandProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="ProductsBrand"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProductsBrandProviderBase ProductsBrandProvider
		{
			get
			{
				if (innerSqlProductsBrandProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProductsBrandProvider == null)
						{
							this.innerSqlProductsBrandProvider = new SqlProductsBrandProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProductsBrandProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlProductsBrandProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProductsBrandProvider SqlProductsBrandProvider
		{
			get {return ProductsBrandProvider as SqlProductsBrandProvider;}
		}
		
		#endregion
		
		
		#region "NewsImageProvider"
			
		private SqlNewsImageProvider innerSqlNewsImageProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="NewsImage"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override NewsImageProviderBase NewsImageProvider
		{
			get
			{
				if (innerSqlNewsImageProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlNewsImageProvider == null)
						{
							this.innerSqlNewsImageProvider = new SqlNewsImageProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlNewsImageProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlNewsImageProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlNewsImageProvider SqlNewsImageProvider
		{
			get {return NewsImageProvider as SqlNewsImageProvider;}
		}
		
		#endregion
		
		
		#region "OrdersOrderProvider"
			
		private SqlOrdersOrderProvider innerSqlOrdersOrderProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="OrdersOrder"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override OrdersOrderProviderBase OrdersOrderProvider
		{
			get
			{
				if (innerSqlOrdersOrderProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlOrdersOrderProvider == null)
						{
							this.innerSqlOrdersOrderProvider = new SqlOrdersOrderProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlOrdersOrderProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlOrdersOrderProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlOrdersOrderProvider SqlOrdersOrderProvider
		{
			get {return OrdersOrderProvider as SqlOrdersOrderProvider;}
		}
		
		#endregion
		
		
		#region "NewsItemProvider"
			
		private SqlNewsItemProvider innerSqlNewsItemProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="NewsItem"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override NewsItemProviderBase NewsItemProvider
		{
			get
			{
				if (innerSqlNewsItemProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlNewsItemProvider == null)
						{
							this.innerSqlNewsItemProvider = new SqlNewsItemProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlNewsItemProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlNewsItemProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlNewsItemProvider SqlNewsItemProvider
		{
			get {return NewsItemProvider as SqlNewsItemProvider;}
		}
		
		#endregion
		
		
		#region "NewsCategoryProvider"
			
		private SqlNewsCategoryProvider innerSqlNewsCategoryProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="NewsCategory"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override NewsCategoryProviderBase NewsCategoryProvider
		{
			get
			{
				if (innerSqlNewsCategoryProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlNewsCategoryProvider == null)
						{
							this.innerSqlNewsCategoryProvider = new SqlNewsCategoryProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlNewsCategoryProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlNewsCategoryProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlNewsCategoryProvider SqlNewsCategoryProvider
		{
			get {return NewsCategoryProvider as SqlNewsCategoryProvider;}
		}
		
		#endregion
		
		
		#region "OrdersDetailsProvider"
			
		private SqlOrdersDetailsProvider innerSqlOrdersDetailsProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="OrdersDetails"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override OrdersDetailsProviderBase OrdersDetailsProvider
		{
			get
			{
				if (innerSqlOrdersDetailsProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlOrdersDetailsProvider == null)
						{
							this.innerSqlOrdersDetailsProvider = new SqlOrdersDetailsProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlOrdersDetailsProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlOrdersDetailsProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlOrdersDetailsProvider SqlOrdersDetailsProvider
		{
			get {return OrdersDetailsProvider as SqlOrdersDetailsProvider;}
		}
		
		#endregion
		
		
		#region "OrderImportProvider"
			
		private SqlOrderImportProvider innerSqlOrderImportProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="OrderImport"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override OrderImportProviderBase OrderImportProvider
		{
			get
			{
				if (innerSqlOrderImportProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlOrderImportProvider == null)
						{
							this.innerSqlOrderImportProvider = new SqlOrderImportProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlOrderImportProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlOrderImportProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlOrderImportProvider SqlOrderImportProvider
		{
			get {return OrderImportProvider as SqlOrderImportProvider;}
		}
		
		#endregion
		
		
		#region "UserLogProvider"
			
		private SqlUserLogProvider innerSqlUserLogProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UserLog"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UserLogProviderBase UserLogProvider
		{
			get
			{
				if (innerSqlUserLogProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUserLogProvider == null)
						{
							this.innerSqlUserLogProvider = new SqlUserLogProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUserLogProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlUserLogProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUserLogProvider SqlUserLogProvider
		{
			get {return UserLogProvider as SqlUserLogProvider;}
		}
		
		#endregion
		
		
		#region "OrderImportDetailProvider"
			
		private SqlOrderImportDetailProvider innerSqlOrderImportDetailProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="OrderImportDetail"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override OrderImportDetailProviderBase OrderImportDetailProvider
		{
			get
			{
				if (innerSqlOrderImportDetailProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlOrderImportDetailProvider == null)
						{
							this.innerSqlOrderImportDetailProvider = new SqlOrderImportDetailProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlOrderImportDetailProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <see cref="SqlOrderImportDetailProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlOrderImportDetailProvider SqlOrderImportDetailProvider
		{
			get {return OrderImportDetailProvider as SqlOrderImportDetailProvider;}
		}
		
		#endregion
		
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
